Overflow detection and clamping with parallel operand processing for fixed-point multipliers

ABSTRACT

A method and apparatus for overflow detection and clamping with parallel operand processing for fixed-point multipliers is disclosed. The invention predicts when a multiplication of a number of operands will exceed a pre-determined number of bits based upon the fixed-point format of the operands. The prediction is performed in parallel with the multiplication of the operands. The multiplication need not be completed in full, but only to the extent to determine whether overflow exists. If an overflow detection occurs, clamping is instituted. The parallel operation of the overflow detection and the multiplication provides a faster clamping circuit than would otherwise be available from a serial multiplication followed by a clamping analysis.

CROSS REFERENCE TO RELATED APPLICATION

This application is a division of U.S. patent application Ser. No. 09/651,159, filed Aug. 30, 2000, now U.S. Pat. No. 7,206,800, issued Apr. 17, 2007.

BACKGROUND OF THE INVENTION

The present invention relates generally to the multiplication and clamping prediction of fixed-point multipliers. More particularly, the invention relates to a method and apparatus for increasing the speed of fixed-point data paths that involve multiplication of operands and parallel overflow detection, and clamping based upon the magnitude of those operands.

Electrical circuits are routinely employed to perform arithmetic operations of operands represented by logical representations. Generally, it is desirable for arithmetic circuitry, and in particular multiplication circuitry, to have the fewest number of bits in order to perform the required calculations. Minimization of the required number of bits facilitates speed of the calculating circuit. However, counter-balancing the desire to have a limited number of bits to perform a given calculation is to avoid answer overflow. Overflow, or the situation in which an answer will exceed the number of bits designed for the answer, is not acceptable, as valuable valid data may be lost in performing the calculations. In circuits that perform calculations with a number of bits that may yield answers that overflow the set number of bits, clamping can be used to ensure that a result that overflows is clamped to a given acceptable value. Normally, the largest magnitude positive or negative representable number is employed as the overflow value. While the employment of a clamping operation is not always desirable, it is generally considered to be better than an overflow that may cause wrapping or undesired bits stored in the particular multiplication circuitry.

Typically, when clamping is desired, it is performed in a sequential fashion. In other words, the arithmetic operation is performed first, and when the result is available, it is then analyzed for overflow. If clamping is required, a clamping value replaces the computed value.

Referring now to FIG. 1, a prior system illustrates the serial processing in which the clamping analysis follows multiplication of particular operands. In this instance, operand 1 (reference numeral 2) and operand 2 (reference numeral 4) are input into an arithmetic operator 6. An output 8 from the arithmetic operator 6 is then directed into an overflow detection scheme 10. Any delays between arithmetic operator 6 and the overflow detection 10 are compounded, with each of their respective delays adding to the overall circuit delay. A clamp value 12 as determined by the overflow detection 10 is input along with a result 14 of the arithmetic operator 6, and a preset clamp value 16 into multiplexer 18. Multiplexer 18 selects the operation result 14 or the preset clamp value 16 in the instance of overflow detection based upon the logical level of clamp bit 12. The result is then output into register 20.

A major problem with sequential operation is that any delays, for both the arithmetic operation and the overflow analysis, tend to compound and therefore yield a relatively slow circuit to the extent that all delays are combined and added together to determine the total circuit delay. In any arithmetic operation, multiplication delays tend to be the largest. Therefore, there exists a need to implement a circuit and method in which arithmetic operations such as multiplication may be performed along with overflow detection. The result is a circuit that eliminates the compounded delay made up of the accumulation of each individual delay associated with sequential overflow analysis and operand processing.

SUMMARY OF THE INVENTION

The present invention provides overflow detection and clamping in parallel with multiplication of fixed-point multiplier operands that overcome the aforementioned problems, and provides a faster circuit than would otherwise be available from serial clamping analysis and arithmetic operation.

In accordance with one aspect of the invention, a method of detecting overflow in a clamping circuit includes inputting a first operand having a fixed-point format (i.e., represented by a fixed number of bits) into the clamping circuit and inputting a second operand having a second fixed-point format into the clamping circuit. A product overflow output is determined based upon the first and second fixed-point format. The method includes predicting whether multiplication of the first operand with the second operand yields a result that exceeds the product overflow output, and performing at least partially the multiplication of the first and second operands. The determining step occurs substantially in parallel with the performing step.

In accordance with another aspect of the invention, a method of clamp detection is disclosed, and includes inputting a first and second operand to both a multiplier and an overflow detection circuit. The method includes multiplying the first and second operands to generate a result not to exceed a pre-determined number of bits, and determining an initial clamping predictor bit based upon the first operand and the second operand. The initial clamping predictor bit is logically ORed with a most significant bit of the result to produce a final clamping predictor bit.

Again, the multiplying and determining steps occur substantially in parallel.

In yet another aspect of the invention, a multiplication overflow detection circuit is disclosed. The circuit includes multiplication circuitry for at least partially multiplying a first and a second operand, overflow detection circuitry receiving the first and second operands that detects whether a result of the multiplication of the first and second operands exceed a maximum representable positive or negative value. The multiplication circuitry and the overflow detection circuitry operate substantially in parallel.

BRIEF DESCRIPTION OF THE DRAWINGS

The drawings illustrate the best mode presently contemplated for carrying out the invention.

In the drawings:

FIG. 1 is a schematic of a prior detection overflow scheme showing serial operand operation and overflow detection.

FIG. 2 is a schematic of parallel operation of an arithmetic operator and the overflow detection in accordance with the present invention.

FIG. 3 is a table illustrating necessary information in determining whether to clamp multiplication of two operands in accordance with one aspect of the present invention.

FIG. 4 is a graph illustrating a simple overflow predictor and the regions necessary for additional overflow prediction calculations.

FIG. 5 shows a schematic of another aspect of the present invention.

FIG. 6 shows a schematic of another aspect of the present invention.

DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT

Referring now to FIG. 2, a clamping system 22 in accordance with the present invention is illustrated. Operand 1 is loaded into register 24 and operand 2 is similarly loaded into register 26. Registers 24, 26 are preferably flip-flops, but any suitable register capable of storing the operands are contemplated. Also, the operands may be passed directly from other arithmetic operators or other related logic, if suitable for the application. Operand 1 and operand 2 are loaded in a fixed-point format.

In fixed-point arithmetic, numbers are represented by zero or one sign bit, zero or more integer bits, and zero or more fractional bits. The integer and fractional bits can be a magnitude, a 1's complement, or a 2's complement value. The most common case is the 2's complement case. A short-hand description is used to denote how many bits there are in each category. This description is typically: <sign-bits>.<integer-bits>.<fractional-bits> or s.i.f. For a signed number with 4 integer bits and 5 fractional bits the notation would be 1.4.5. For an unsigned number with 6 integer bits and 3 fractional bits the notation would be 0.6.3, and often the leading zero is omitted to yield 6.3.

For a given fixed-point representation s.i.f there are associated numerical properties, (and assuming that the 2's complement is used):

Largest positive number representable: 2^(i)−2^(−f)

Largest (magnitude) negative number representable: −2i

Smallest positive number representable: 2^(−f)

Smallest (magnitude) negative number representable: −2^(−f)

When fixed-point numbers are used in arithmetic operations such as additions, subtractions, and multiplications, the results generally require more bits to avoid overflow.

The rules for the two types of operations are:

1. Addition and subtraction:

If both inputs are of the same format s.i.f then the output requires s.(i+1).f to avoid overflow.

If the inputs are of different formats s.i1.f1 and s.i2.f2, then choose i=max(i1,i2) and f=max(f1,f2). Then the output requires s.(i+1).f bits to avoid overflow.

2. Multiplication:

If the inputs are of the same format s.i.f then the output requires s.(2*i+1).(2*f) to avoid overflow.

If the inputs are of different formats s.i1.f1 and s.i2.f2, then the output requires s.(i1+i2+1).(f1+f2) to avoid overflow.

Since multiplication most often produces the need for overflow detection and clamping, it is preferred that the present invention be utilized in multiplication of operand 1 and operand 2, with each operand in a fixed-point format. As FIG. 2 demonstrates, operand 1 and operand 2 are both supplied to overflow detection circuit 28 as well as an arithmetic operator or multiplier 30. The multiplier 30 takes operand 1 and operand 2 and determines at least a partial product of the binary operands. It is important to note that the multiplier does not have to be full precision. It need only be twice the precision that is desired to be represented in the final result. For example, if it is desired to multiply two operands, each having eight bits, when the multiplication of eight bits and eight bits occurs, the answer will have sixteen bits of output. However, if it is only desired to have eight bits to come out in the final output, when the multiplication could actually generate up to sixteen bits, the multiplier will be used to generate nine bits. The nine bits represent twice the desired output range. Therefore, in the above-identified example, the answer will have a nine-bit result instead of the full sixteen-bit result. The final seven bits of the multiplication are not necessarily calculated.

Operand 1 and operand 2 are also presented to the overflow detection logic. The overflow detection circuit 28 occurs in parallel with the multiplier 30 operation. It is the substantially simultaneous processing of the overflow detection and the multiplication that produces the efficiencies in processing time for the circuit. Also, it is the fact that the full product need not necessarily be calculated that results in further efficiencies in processing time.

The overflow detection circuit 28 considers the two input operands and predicts whether or not they will cause the product to overflow. The overflow detection circuit 28 predicts when the product is going to be greater than or equal to two times the maximum desired value. This handles most of the clamping cases, but it is not exact. To get exact clamping, the product is computed to the (io+1)'th integer bit, and the most significant bit 37 of the product is used to finally determine whether or not to clamp.

The fixed-point format of the two inputs and the desired output must be known. These formats are denoted as:

Operand1: s.i1.f1

Operand2: s.i2.f2

Output: s.io.fo

The product of the two input operands will require s.(i1+i2+1).(f1+f2) to avoid overflow. The assumption is that io<i1+i2+1, (because, if io>i1+i2+1 then an overflow cannot occur).

EXAMPLE

Consider the simple case of two positive input operands that yield a positive product. The maximum positive number that can be represented by the desired output representation is:

2^(io)−2^(−fo)

Therefore, any combination of input operands that yields a product greater than or equal to the maximum value should be clamped to the maximum positive value:

Output=op1*op2 if (op1*op2)<2^(io)−2^(−fo)

Output=2^(io)−2^(−fo) if (op1*op2)≧2^(io)−2^(−fo)

The result 32 of multiplier 30 (which will in a preferred embodiment be a partial multiplication) is output from the multiplier 30. The overflow detection circuit 28 outputs result (clamp bit 34) from its overflow detection circuitry, and as a result of a logical level of a clamp bit 34 it is determined whether clamping will occur. The most significant bit 37 (on line 36) of result 32 is logically ORed with clamp bit 34 through OR gate 38. Therefore, if any of clamp bit 34 or the most significant bit 37 is logically high, clamping will occur and a clamping signal 40 is output from OR gate 38. The clamping signal 40 is input into multiplexer 42. Result 32 of the multiplication is also input into multiplexer 42. Clamp value 44 is preferably hard-wired into multiplexer 42. The value of clamp value 44 is predetermined depending on the number of bits in operand 1 and operand 2. Preferably, the clamp value is the maximum representable positive or negative value. It is contemplated that in selecting a positive or negative value for operand 1 or operand 2, the MSB (most significant bit) of each register 24, 26 could be exclusively ORed (XOR) together such that if the operands are of a different sign, the negative clamping value will be used for clamp value 44. Consequently, if both operands are of the same sign, the positive value for clamp value 44 will be used. Multiplexer 42 will select either result 32 or clamp value 44 depending upon the logical level of clamp signal 40, and will output the selection into output register 46.

Referring now to FIG. 3, a binary representation of several scenarios are given.

Take the case of two 1.6.4 operands, multiply them and return the product clamped to a 1.6.4 number. The maximum representable value in the output is 2⁶−=64−1/16=63.9375. Some simple cases exist:

If op1≧32 and op2≧2 then clamp (45 a)

If op1≧16 and op2≧4 then clamp (45 b)

If op1≧8 and op2≧8 then clamp (45 c)

If op1≧4 and op2≧16 then clamp (45 d)

If op1≧2 and op2≧32 then clamp (45 e)

The binary representation of these scenarios is given in FIG. 3.

It can be seen that the number of leading zeros in the integer portion of the operands is indicative of the magnitude of the operands, and by adding the number of leading zeros of both op1 (47) and op2 (49), there is a constant number of leading zeros 51. Therefore, the fixed-point format of the operands will determine the constant number of leading zeros to determine whether clamping occurs. Clamping must occur when:

If (<op1 leading zeros>+<op2 leading zeros>)≦4 then clamp

Else don't clamp

This relatively simple predictor works for a substantial portion of products, but it is not completely accurate. If only this predictor were used, it would be possible to get products that could be as much as twice the desired max value, i.e., (max product given simple predictor)<2*(desired max value)

Therefore, to get an accurate clamp predictor, the above simple predictor is used, and the multiplication generates a result that is of format s.(io+1).fo. Then, for positive operands, an overflow is detected by ORing together the MSB of the integer bits and the clamp-prediction.

Referring now to FIG. 4, a graph is shown showing the regions of products that are clamped by the initial clamp predictor. The broad region covered by the simple, initial clamp predictor is shown generally by the numeral 50. Regions 52 represent those products that require the io+1 integer bits of the product to get accurate overflow detection and therefore require more precise clamp prediction. Region 54 represents the region where clamping is not needed because the product does not exceed the desired number of bits. However, this graph is representative of only one particular set of operands (both positive). Other predictors will produce different data depending upon the signs of the operands.

General Case

The general case consists of three subcases depending on the signs of the input operands:

Case 1: (op1>0 and op2>0)

Case 2: (op1<1 and op2<1)

Case 3: (op1>0 and op2<1) or (op1<0 and op2>0)

Each of these cases will be examined in turn.

Case 1: Both Operands are Positive

The simple clamp predictor is:

If the sum of the input operands' leading zeros is less than or equal to (i1−io)+(i2−io)+(io−2)=i1+i2−io−2 then the circuit must clamp.

The accurate clamp prediction must use the (io+1) bit of the product, i.e., the product must be computed at least to (io+1) integer bits. This bit is ORed logically with the simple clamp predictor to yield the accurate clamp determination.

Case 2: Both Operands are Negative

When both operands are negative, their product is positive. Therefore, if an overflow case exists we clamp to the same value as mentioned before, namely:

2^(io)−2^(−fo)

When both operands are negative the simple clamp predictor must count leading ones in the input operands. If the sum of the input operands' leading ones is less than or equal to (i1−io)+(i2−io)+(io−1)=i1+i2−io−1 then the circuit must clamp.

However, there is an additional case, when both operands have only zeros after the leading ones (e.g., 111100.0000) then the simple clamp predictor should also clamp. This is like counting leading zeros on a bit-reversed version of each input. If the trailing zeros plus the leading ones equal (i+f) for both inputs then clamp. As before, the accurate clamp prediction must use the (io+1) bit of the product, i.e., the product must be computed at least to (io+1) integer bits. This bit is ORed logically with the simple clamp predictor to yield the accurate clamp determination.

Case 3: Only One of the Operands is Negative

When only one of the input operands is negative, their product will be negative. Therefore, if an overflow case exists we clamp to the largest (magnitude) negative value, namely, −2^(io).

In this case, the simple clamp predictor must count leading ones for the negative input, and leading zeros for the positive input. Then, if the sum of the inputs' leading ones and leading zeros is less than or equal to (i1−io)+(i2−io)+(io−2)=i1+i2−io−2 then the circuit must clamp.

As before, the accurate clamp prediction must use the (io+1) bit of the product, i.e., the product must be computed at least to (io+1) integer bits. This bit is logically inverted, then ORed logically with the simple clamp predictor to yield the accurate clamp determination.

Referring now to FIG. 5, another embodiment of the present invention is shown. In this embodiment, the clamp bit may be stored in a clamp bit register 60 and the result of the multiplier operation may be stored in multiplier result register 62. In this embodiment, after one of the result register 62 or clamp value 64 is selected, other logic 68 is introduced to process the output 66 as part of a pipelining stage. The pipelining stage enables further processing of a partial result if the computation is not completed in a single clock cycle. The clamp prediction along with a partial result is then saved for the following clock cycle where completion of the clamping prediction will occur in the second clock cycle.

The initial clamp predictor may be utilized as soon as the two operands are available. The final clamp predictor must occur after the result of the multiplier has completed its partial computation to the appropriate necessary bit. Therefore, the simple clamp prediction occurs at the same time as the multiplier as manipulating operand 1 and operand 2.

Although two operands are shown, it is contemplated by the present invention that any number of operands may be used as inputs to the multiplier operation. In addition, the multiplication may occur in several stages with other multiplications coming before or after in a similar manner. The cloud of logic represents other multiplications, other additions or other logic operations on the result 66 of the multiplexer.

The present invention has been described in terms of the preferred embodiment, and it is recognized that equivalents, alternatives, and modifications, aside from those expressly stated, are possible and within the scope of the appending claims. 

1. A method of detecting overflow in a clamping circuit, the method comprising: inputting a first operand having a first fixed-point format denoted by s.i1.f1 into the clamping circuit; inputting a second operand having a second fixed-point format denoted by s.i2.f2 into the clamping circuit; determining a clamp bit based upon the first operand and the second operand; performing at least partially a multiplication operation of the first operand and the second operand to produce a multiplication result having a number of bits that is at least (io+1) when a predetermined output representation for a final result has a fixed-point format denoted by s.io.fo, and io<i1+i2+1, wherein the determining the clamp bit occurs independent from and substantially in parallel with the performing the at least partially a multiplication operation; predicting whether the result of the multiplication operation needs to be clamped given the predetermined output, wherein a prediction is based on the clamp bit and a most significant bit (MSB) of the multiplication result; and inputting the multiplication result and a predetermined clamp value into a multiplexor for selection therebetween based upon the prediction.
 2. The method of claim 1, wherein the determining and performing occur within a first clock cycle, and wherein the predicting occurs within a second clock cycle.
 3. The method of claim 1, wherein the performing produces a multiplication result having a number of bits that is equal to (io+1).
 4. The method of claim 1, wherein the performing produces a multiplication result having a number of bits that is at least (io+1) but less than (i1+i2+1).
 5. The method of claim 1, wherein the clamp bit and the MSB of the multiplication result are logically ORed together to produce a final clamping predictor bit.
 6. The method of claim 1, wherein the clamp bit is determined based upon at least one of a number of logical ones and a number of logical zeros in each of the operands and summing the number of logical ones or number of logical zeros to determine whether the sum exceeds a pre-determined number.
 7. The method of claim 1, wherein inputting the first operand and inputting the second operant comprise passing the first operand and the second operand directly from another logic device.
 8. A method of detecting overflow in a clamping circuit, the method comprising: inputting a first operand (op1) and second operand (op2) into overflow detection circuitry and a multiplier, the first operand having a first fixed-point format denoted by s.i1.f1 and the second operand having a second fixed-point format denoted by s.i2.f2; determining a clamp bit with the overflow detection circuitry based upon the first operand and the second operand within a first clock cycle; performing at least partially a multiplication operation of the first and second operands within the first clock cycle to generate a multiplication result having a number of bits that is at least (io+1) when a predetermined output representation for a final result has a fixed-point format denoted by s.io.fo, and io<i1+i2+1; and determining whether the multiplication result will yield a result that exceeds a given output representation based on the clamp bit and a most significant bit (MSB) of the multiplication result within a second clock cycle.
 9. The method of claim 8, wherein values of the first operand (op1) and second operand (op2) are selected from the group consisting of (op1>0 and op2≧0), (op1<1 and op2<1), (op1>0 and op2<1), and (op1<0 and op2≧0).
 10. A method of clamp detection, the method comprising: inputting a first operand and a second operand to both a multiplier and an overflow detection circuit, wherein the first operand has a fixed point format denoted by s.i1.f1, and the second operand has a fixed point format denoted by s.i2.f2; performing at least partially a multiplication operation of the first and second operands to generate a multiplication result not to exceed a pre-determined number of bits and having a number of bits that is at least (io+1) when a predetermined output representation for a final result has a fixed-point format denoted by s.io.fo, and io<i1+i2+1; determining an initial clamping predictor bit based upon the first operand and the second operand, wherein the performing the at least partially a multiplication operation and the determining the initial clamping predictor bit occur independently and substantially in parallel; logically ORing the initial clamping predictor bit and a most significant bit (MSB) of the multiplication result to produce a final clamping predictor bit; and inputting the multiplication result and a predetermined clamp value into a multiplexor for selection therebetween based on the final clamping predicator bit.
 11. The method of claim 10, further comprising hard-wiring the predetermined clamp value into the multiplexor.
 12. A multiplication overflow detection circuit, comprising: multiplication circuitry configured to at least partially multiply a first operand in a fixed point format denoted by s.i1.f1 and a second operand in a fixed point format denoted by s.i2.f2 to produce a multiplication result; and overflow detection circuitry configured to receive the first operand and the second operand and to determine whether the multiplication result exceeds a maximum representable positive or negative value based upon at least one of a number of logical ones or a number of logical zeros in each of the first operand and the second operand and a sum of the number of logical ones or a number of logical zeros to determine whether the sum exceeds a pre-determined number, wherein the multiplication circuitry and the overflow detection circuitry operate independently and substantially in parallel; a multiplexor connected to the multiplication circuitry and the overflow detection circuitry, the multiplexor configured to receive the multiplication result and at least one predetermined clamp value for selection therebetween.
 13. An overflow detection circuit, comprising: a first register configured to store a first operand in a fixed point format denoted by s.i1.f1; a second register configured to store a second operand in a fixed point format denoted by s.i2.f2; overflow detection circuitry configured to detect an overflow of a multiplication result of the first operand and the second operand and producing a clamp bit; a multiplier configured to at least partially multiply the first operand and the second operand and to generate a multiplication result not to exceed a pre-determined number of bits, wherein the multiplier is configured to operate independently and substantially in parallel with the overflow detection circuitry; a clamp bit register configured to store the clamp bit from the overflow detection circuitry; a result register connected to the multiplier and configured to store the multiplication result of the first operand and the second operand; and a multiplexor connected to the clamp bit register and the result register, the multiplexor configured to select between the multiplication result and a predetermined clamp value based at least in part on the clamp bit.
 14. The overflow detection circuit of claim 13, wherein each of the first register and the second register comprise at least one flip flop.
 15. The overflow detection circuit of claim 13, wherein integer bits and fractional bits of the fixed point format are selected from the group consisting of a magnitude, a 1's complement value, and a 2's complement value.
 16. A method of clamping fixed-point multipliers utilizing an apparatus operable for implementing a method, comprising: providing a first operand (op1) in a first fixed-point format denoted by s.i1.f1 into a clamping circuit; providing a second operand (op2) in a second fixed-point format denoted by s.i2.f2 into the clamping circuit; at least partially multiplying the first operand with the second operand to produce a multiplication result; determining whether the multiplication result will exceed a representable value; exclusively ORing a most significant bit of the first operand and the second operand to determine a clamping value; substituting the multiplication result with the clamping value when it is determined that the multiplication result will exceed the representable value; and discontinuing the multiplying if the multiplication result exceeds the representable value, wherein the at least partially multiplying and the determining whether the multiplication result will exceed the representable value occur substantially in parallel.
 17. The method of claim 16, wherein values for the first operand (op1) and the second operand (op2) are selected from the group consisting of (op1>0 and op2≧0), (op1<1 and op2<1), (op1>0 and op2<1), and (op1<0 and op2≧0).
 18. A method of processing multiplier operands utilizing an apparatus operable for implementing a method, comprising: performing at least a partial multiplication of a plurality of operands to produce a product, each operand having a fixed-point format; determining whether the product will exceed a pre-determined limit; and discontinuing the performing the at least partial multiplication if the product exceeds the pre-determined limit, the performing and the determining occurring independently and substantially in parallel.
 19. The method of claim 18, further comprising pipelining the product for processing within a subsequent clock cycle.
 20. The method of claim 18, further comprising selecting between the product and a pre-determined clamp value responsive to the determination whether product will exceed the pre-determined limit.
 21. The method of claim 20, wherein selecting between the product and the pre-determined clamp value comprises inputting the product and the pre-determined clamp value into multiplexor.
 22. The method of claim 21, wherein selecting between the product and the pre-determined clamp value comprises selecting the pre-determined claim value as one of a positive clamp value and a negative clamp value. 